using System;
using System.Collections.Generic;
using System.Text;

namespace GoogleNet
{
    /// <summary>
    /// This element draws an image overlay draped onto the terrain.
    /// </summary>
    public class KmlGroundOverlay: KmlOverlay, IKmlElement
    {
        private string tagName = "GroundOverlay";

        #region AltitudeMode
        KmlAltitudeModes altitudeMode = KmlAltitudeModes.clampToGround;

        /// <summary>
        /// Gets or sets the altitude mode, which specifies how altitude components in the coordinates element are interpreted.
        /// </summary>
        /// <value>The altitude mode.</value>
        public KmlAltitudeModes AltitudeMode
        {
            get { return altitudeMode; }
            set { altitudeMode = value; }
        }
        #endregion

        #region Altitude
        private float altitude;

        /// <summary>
        /// Specifies the distance above the earth's surface, in meters, and is interpreted according to altitudeMode> 
        /// </summary>
        /// <value>The altitude.</value>
        public float Altitude
        {
            get { return altitude; }
            set { altitude = value; }
        }
        #endregion

        #region LatLonBox
        private KmlLatLonBox latLonBox;

        /// <summary>
        /// Specifies where the top, bottom, right, and left sides of a bounding box for the ground overlay are aligned. 
        /// </summary>
        /// <value>The bounding box for the ground overlay.</value>
        public KmlLatLonBox LatLonBox
        {
            get { return latLonBox; }
            set { latLonBox = value; }
        } 
        #endregion

        #region IKmlElement Members

        /// <summary>
        /// Name of the KML tag for this specific element.
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        string IKmlElement.TagName
        {
            get { return tagName; }
        }

        #endregion

        #region IKmlGenerator Members

        /// <summary>
        /// Generates the KML for this element including its child elements.
        /// </summary>
        /// <param name="writer">The XML writer that will be used to generate the KML.</param>
        public override void GenerateKml(System.Xml.XmlTextWriter writer)
        {
            writer.WriteStartElement(tagName);
            latLonBox.GenerateKml(writer);

            if(altitude != 0)
                writer.WriteElementString("altitude", this.altitude.ToString());

            if(altitudeMode != KmlAltitudeModes.absolute)
                writer.WriteElementString("altitudeMode", this.altitude.ToString());

            writer.WriteEndElement();
        }

        #endregion
    }
}
